import {Component, Input, OnInit} from '@angular/core';
import {AlertService} from "../../../../services/alert.service";
import {AdminService} from "../../../../services/admin.service";
import {BakeTestRecord} from "../../../../model/BakeTestRecord";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-baketestrecordedit',
  templateUrl: './baketestrecordedit.component.html',
  styleUrls: ['./baketestrecordedit.component.css']
})
export class BaketestrecordeditComponent implements OnInit {
  @Input()id:string
  b:BakeTestRecord
  jyrArray:Array<any>
  constructor(  private adminService:AdminService,private alertService:AlertService,
                private authService:AuthService) {
    this.b = new BakeTestRecord()
    this.jyrArray=Array<any>()
  }

  ngOnInit(): void {
    this.getBakeRecord()
    this.getjyArray()
  }

  getBakeRecord(){
    this.adminService.getBakeTestRecordByid(this.id).then((data:any)=>{
      if(data.msg =="ok"){
        this.b = data.obj
      }else{
        this.alertService.showError("根据id获取烘焙检验失败")
      }
    })
  }

  getjyArray(){
    this.authService.getMemberListByRole("8f716f753b494efea3b5e1de73f4a347").then((data:any)=>{
      if(data.msg == "ok"){
        this.jyrArray = data.list
      }else{
        this.alertService.showError("获取检验人数组失败")
      }
    })
  }

  save(){
    this.adminService.saveBaketest(this.b).then((data:any)=>{
      if(data.msg =="ok"){
        this.alertService.showSuccess("设置烘焙检验成功")
      }else{
        this.alertService.showError("设置烘焙检验失败")
      }
    })
  }
}
